home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
emulator
/
bsvc-1.000
/
bsvc-1
/
bsvc-1.0.4
/
src
/
UI
/
main.tk
< prev
next >
Wrap
Text File
|
1995-07-26
|
44KB
|
1,257 lines
#!/usr/local/bin/wish -f
###############################################################################
# $Id: main.tk,v 1.6 1995/06/29 23:06:56 bmott Exp $
###############################################################################
# main.tk - BSVC user interface
#
# Copyright 1993
# Bradford W. Mott
# September 18,1993
###############################################################################
# $Log: main.tk,v $
# Revision 1.6 1995/06/29 23:06:56 bmott
# Fixed "Insert Registers..." in trace window bug
#
# Revision 1.5 1995/01/01 02:59:39 bmott
# Added Home Page option to the help menu and changed the version number
#
# Revision 1.4 1994/09/13 23:25:10 bmott
# Changed file selector to BtkFileSelector.
# Modified trace preferences to fill the width of the window.
#
# Revision 1.3 1994/08/22 07:43:31 bmott
# Modified startup of the program to see if a setup file should be loaded
#
# Revision 1.2 1994/06/23 00:20:12 bmott
# Changed the breakpoint dialog to be a child of the main window.
# Changed the name of some of the buttons on the Edit Setup dialog.
#
# Revision 1.1 1994/02/18 20:29:29 bmott
# Initial revision
#
###############################################################################
## Include utilities
source $Program(LibDir)/BtkFileSelector.tk
source $Program(LibDir)/memory.tk
source $Program(LibDir)/listing.tk
source $Program(LibDir)/tools.tk
source $Program(LibDir)/help.tk
## Important globals
set Program(Name) "BSVC"
set Program(Version) "1.1"
set Simulator(Prompt) "Ready!"
wm title . "$Program(Name)"
wm iconname . $Program(Name)
wm iconbitmap . "@$Program(BitmapDir)/bsvc_icon.xbm"
wm grid . 1 1 1 1
###############################################################################
# Called when the user selects the quit menu options
###############################################################################
proc QuitBSVC {} {
StopSimulator
exit
}
###############################################################################
# The About Dialog
###############################################################################
proc About {} {
global Program
catch {destroy .about}
toplevel .about
wm title .about "About $Program(Name)"
wm iconname .about "About $Program(Name)"
label .about.bmott -relief raised -bitmap @$Program(BitmapDir)/b-logo.xbm
frame .about.bsvc -relief flat -borderwidth 2
label .about.bsvc.bitmap -relief raised -bitmap @$Program(BitmapDir)/bsvc.xbm
message .about.bsvc.message1 \
-text "A Microprocessor Simulation Framework" \
-width 3i -justify center
message .about.bsvc.message2 \
-text "By: Bradford W. Mott" \
-width 3i -justify center
message .about.bsvc.message3 \
-text "Copyright (c) 1993,1994,1995\n\nVersion $Program(Version)" \
-width 3i -justify center
button .about.bsvc.ok -text "Okay" -command "destroy .about"
pack .about.bsvc.bitmap -side top -padx 2 -pady 2
pack .about.bsvc.message1 -side top -padx 2 -pady 6
pack .about.bsvc.message2 -side top -padx 2 -pady 6
pack .about.bsvc.message3 -side top -padx 2 -pady 6
pack .about.bsvc.ok -side bottom -padx 2 -pady 2 -fill x
pack .about.bmott -side left -padx 2 -pady 2 -fill y -expand 1
pack .about.bsvc -side left -padx 2 -pady 2 -fill y -expand 1
}
###############################################################################
# Set the application's widgets to the correct mode
###############################################################################
proc SetApplicationMode {mode} {
if {$mode=="SimulationMode"} {
.mainMenu.simulator configure -state normal
.mainMenu.simulator.menu enable "Save Setup..."
.mainMenu.simulator.menu enable "Edit Setup..."
.mainMenu.system configure -state normal
.mainMenu.help configure -state normal
.systemResources.registers.popup configure -state normal
.systemResources.statistics.popup configure -state normal
.systemControl.singleStep configure -state normal
.systemControl.step configure -state normal
.systemControl.run configure -state normal
.systemControl.breakpoints configure -state normal
.systemOutput.popup configure -state normal
}
if {$mode=="StartupMode"} {
.mainMenu.simulator configure -state normal
.mainMenu.simulator.menu disable "Save Setup..."
.mainMenu.simulator.menu disable "Edit Setup..."
.mainMenu.system configure -state disabled
.mainMenu.help configure -state normal
.systemResources.registers.popup configure -state disabled
.systemResources.statistics.popup configure -state disabled
.systemControl.singleStep configure -state disabled
.systemControl.step configure -state disabled
.systemControl.run configure -state disabled
.systemControl.breakpoints configure -state disabled
.systemOutput.popup configure -state disabled
}
}
###############################################################################
# Send a line of input to the simulator
###############################################################################
proc PutLine {line} {
global Simulator
puts $Simulator(Pipe) $line
flush $Simulator(Pipe)
}
###############################################################################
# Get a line of output from the simulator
###############################################################################
proc GetLine {} {
global Simulator
return [gets $Simulator(Pipe)]
}
###############################################################################
# Get a list of output from the simulator
###############################################################################
proc GetList {} {
global Simulator
set list ""
while {1} {
set input [gets $Simulator(Pipe)]
if {[string compare $input $Simulator(Prompt)]!="0"} {
lappend list "$input"
} else {
return $list
}
}
}
###############################################################################
# Stop the simulator and clean up
###############################################################################
proc StopSimulator {} {
global Simulator
## Change application to startup mode
SetApplicationMode {StartupMode}
## Shutdown the simulator process by sending Exit Command
catch {PutLine "Exit"}
catch {unset Simulator(Pid)}
## Close the pipe to the simulator
catch {close $Simulator(Pipe)}
catch {unset Simulator(Pipe)}
## destory old values
catch {unset Simulator(ProgramName)}
catch {unset Simulator(Greeting)}
catch {unset Simulator(NumberOfAddressSpaces)}
catch {unset Simulator(Granularity)}
catch {unset Simulator(TraceRecord)}
catch {unset Simulator(TraceEntries)}
## Clean up the windows
.systemResources.registers.list delete 0 end
.systemResources.statistics.list delete 0 end
.systemOutput.text delete 1.0 end
## Close down the memory and program listing windows
CloseMemoryViewer
CloseProgramListing
}
###############################################################################
# Start the simulator
###############################################################################
proc StartSimulator {name} {
global Simulator
global env
## Check to make sure the simulator exists and is executable
set paths [concat . [split "$env(PATH)" ":"]]
set does_not_exists 1
foreach i $paths {
if {[file executable $i/$name] && [file isfile $i/$name]} {
set does_not_exists 0
}
}
if {$does_not_exists} {
ChildAlertDialog {} "Could not find the requested simulator to execute!!!\n\n($name)"
return 0
}
## Open a pipe to the simulator (read & write)
if {[catch {open "|$name" "r+"} Simulator(Pipe)]} {
catch {close $Simulator(Pipe)}
ChildAlertDialog {} {Problem opening pipe to the simulator!!!}
return 0
}
## Make sure the program is a BSVC Simulator!!!
if {[string compare [GetLine] "BSVC Simulator"]!=0} {
close $Simulator(Pipe)
ChildAlertDialog {} {That program does not seem to be a valid BSVC simulator!!!}
return 0
} else {
set Simulator(ProgramName) "$name"
set Simulator(Greeting) [GetList]
set Simulator(Pid) [pid $Simulator(Pipe)]
PutLine "ListNumberOfAddressSpaces"
set Simulator(NumberOfAddressSpaces) [lindex [GetList] 0]
PutLine "ListGranularity"
set Simulator(Granularity) [lindex [GetList] 0]
PutLine "ListExecutionTraceRecord"
set Simulator(TraceRecord) [lindex [GetList] 0]
PutLine "ListDefaultExecutionTraceEntries"
set Simulator(TraceEntries) [lindex [GetList] 0]
return 1
}
}
###############################################################################
# Detach all of the devices from the given address space
###############################################################################
proc DetachAllDevices {address_space} {
## Get a list of all attached devices
PutLine "ListAttachedDevices $address_space"
set number_of_devices [llength [GetList]]
## Remove each device from the address space
for {set t [expr $number_of_devices-1]} {$t>=0} {set t [expr $t-1]} {
## Send the detach command to the simulator
PutLine "DetachDevice $address_space $t"
## Output any errors to the user
set errs [lindex [GetList] 0]
if {$errs!=""} { ChildAlertDialog {} $errs }
}
}
###############################################################################
# Detach the indexed device from the simulator
###############################################################################
proc DetachDevice {address_space index} {
## Send the detach command to the simulator
PutLine "DetachDevice $address_space $index"
## Output any errors to the user
set errs [lindex [GetList] 0]
if {$errs!=""} { ChildAlertDialog {} $errs }
}
###############################################################################
# Attach the named device to the simulator
###############################################################################
proc AttachDevice {address_space name} {
## Get the device's script
PutLine "ListDeviceScript $name"
set script [GetList]
## Get the script in a form that can be executed by 'eval'
set t ""
foreach i $script { set t "$t\n$i" }
## Evaluate the script and execute the device setup
if {[catch {eval "$t"}]==0} {
## Call the DeviceSetup procedure that should have just been created
set device_args [DeviceSetup]
if {$device_args!=""} {
PutLine "AttachDevice $address_space $name \{$device_args\}"
set errs [lindex [GetList] 0]
if {$errs!=""} { ChildAlertDialog {} $errs }
}
} else {
ChildAlertDialog {} {The device script cannot be executed!!!}
}
}
###############################################################################
# RefreshEditSetupLists
###############################################################################
proc RefreshEditSetupLists {addr_space} {
global Simulator
## Empty available list
.editSetup.availableDevices.list delete 0 end
## Fill in the available device list
PutLine {ListDevices}
foreach i [GetList] {
.editSetup.availableDevices.list insert end $i
}
## Empty attached list
.editSetup.attachedDevices.list delete 0 end
## Fill in the attached device list
PutLine "ListAttachedDevices $addr_space"
foreach i [GetList] {
.editSetup.attachedDevices.list insert end $i
}
}
###############################################################################
# Change the edit setup address space
###############################################################################
proc ChangeEditSetupAddressSpace {value} {
global CurrentEditSetupAddressSpace
set CurrentEditSetupAddressSpace $value
RefreshEditSetupLists $CurrentEditSetupAddressSpace
}
###############################################################################
# Handle Edit Setup menu selection
###############################################################################
proc EditSetup {} {
global Simulator
global CurrentEditSetupAddressSpace
set CurrentEditSetupAddressSpace 0
## Create frame for edit dialog
frame .editSetup -relief raised -borderwidth 3
## Create the "Dismiss" button
button .editSetup.done -text "Dismiss" -command {destroy .editSetup}
pack .editSetup.done -side bottom -fill x -padx 4 -pady 4
## Create the "Attached Devices" area (list,scroll, & buttons)
frame .editSetup.attachedDevices
label .editSetup.attachedDevices.label -text "Attached Devices" \
-relief raised
scrollbar .editSetup.attachedDevices.scroll -relief raised \
-command ".editSetup.attachedDevices.list yview"
listbox .editSetup.attachedDevices.list -relief raised \
-yscroll ".editSetup.attachedDevices.scroll set"
tk_listboxSingleSelect .editSetup.attachedDevices.list
frame .editSetup.attachedDevices.buttons
button .editSetup.attachedDevices.buttons.remove -text "Detach" \
-command {
if {[llength [.editSetup.attachedDevices.list curselection]]!=0} {
DetachDevice $CurrentEditSetupAddressSpace \
[.editSetup.attachedDevices.list curselection] ;
RefreshEditSetupLists $CurrentEditSetupAddressSpace ;
RefreshMemoryViewer
}
}
button .editSetup.attachedDevices.buttons.removeAll -text "Detach All" \
-command {DetachAllDevices $CurrentEditSetupAddressSpace ;
RefreshEditSetupLists $CurrentEditSetupAddressSpace;
RefreshMemoryViewer}
pack .editSetup.attachedDevices.buttons.remove -side left \
-fill x -expand 1
pack .editSetup.attachedDevices.buttons.removeAll -side left \
-fill x -expand 1
pack .editSetup.attachedDevices.label -side top -fill x
pack .editSetup.attachedDevices.buttons -side bottom -fill x -expand 1
pack .editSetup.attachedDevices.scroll -side left -fill y
pack .editSetup.attachedDevices.list -side left -fill y
## Create the "Available Devices" area (list,scroll, & buttons)
frame .editSetup.availableDevices
label .editSetup.availableDevices.label -text "Available Devices" \
-relief raised
scrollbar .editSetup.availableDevices.scroll -relief raised \
-command ".editSetup.availableDevices.list yview"
listbox .editSetup.availableDevices.list -relief raised \
-yscroll ".editSetup.availableDevices.scroll set"
tk_listboxSingleSelect .editSetup.availableDevices.list
bind .editSetup.availableDevices.list <Double-1> {
if {[llength [.editSetup.availableDevices.list curselection]]!=0} {
AttachDevice $CurrentEditSetupAddressSpace \
[.editSetup.availableDevices.list get \
[.editSetup.availableDevices.list curselection]] ;
RefreshEditSetupLists $CurrentEditSetupAddressSpace ;
RefreshMemoryViewer
}
}
frame .editSetup.availableDevices.buttons
button .editSetup.availableDevices.buttons.add -text "Attach" \
-command {
if {[llength [.editSetup.availableDevices.list curselection]]!=0} {
AttachDevice $CurrentEditSetupAddressSpace \
[.editSetup.availableDevices.list get \
[.editSetup.availableDevices.list curselection]];
RefreshEditSetupLists $CurrentEditSetupAddressSpace ;
RefreshMemoryViewer
}
}
pack .editSetup.availableDevices.buttons.add -side left \
-fill x -expand 1
pack .editSetup.availableDevices.label -side top -fill x
pack .editSetup.availableDevices.buttons -side bottom -fill x -expand 1
pack .editSetup.availableDevices.scroll -side left -fill y
pack .editSetup.availableDevices.list -side left -fill y
pack .editSetup.attachedDevices -side left -padx 4 -pady 4
pack .editSetup.availableDevices -side left -padx 4 -pady 4
## If there are multiple address spaces then create a scale
if {$Simulator(NumberOfAddressSpaces) > 1} {
frame .editSetup.addressSpace
label .editSetup.addressSpace.label -text "Address Space" \
-relief raised
scale .editSetup.addressSpace.scale -from 0 -showvalue 1 \
-tickinterval 1 -to [expr $Simulator(NumberOfAddressSpaces)-1] \
-relief raised -command {ChangeEditSetupAddressSpace}
pack .editSetup.addressSpace.label -side top -fill x
pack .editSetup.addressSpace.scale -side top -fill both -expand 1
pack .editSetup.addressSpace -side left -fill y -padx 4 -pady 4
}
place .editSetup -relx 0.5 -rely 0.5 -anchor center
RefreshEditSetupLists $CurrentEditSetupAddressSpace
## Make this a modal dialog
tkwait visibility .editSetup
grab set .editSetup
tkwait window .editSetup
}
###############################################################################
# Handle New Setup (Ask for simulator's name and goto edit screen)
###############################################################################
proc NewSetup {} {
global Simulator
## Shutdown any running simulator
StopSimulator
## Set the application to startup mode
SetApplicationMode {StartupMode}
set ReturnValue [ChildEntryDialog \
{} {What simulator do you want to use? (i.e. Sim68000)} {[.]*}]
## Check to see if cancel was pressed
if {[string length $ReturnValue]==0} {
return
} else {
## Attempt to start the simulator process
if {[StartSimulator $ReturnValue]} {
SetApplicationMode {SimulationMode}
## Decided if the statistics list should be displayed
if {[RefreshStatisticsList] == "0"} {
pack forget .systemResources.statistics
} else {
pack .systemResources.statistics -after .systemResources.registers \
-side left -fill y
}
RefreshRegisterList
EditSetup
} else {
}
}
}
###############################################################################
# Clear the simulator's Statistics
###############################################################################
proc ClearStatistics {} {
## Tell the simulator to clear the statistics
PutLine {ClearStatistics}
GetList
## Update the statistics list
RefreshStatisticsList
}
###############################################################################
# Refresh the Statistics List (returns 0 if a list does not exists)
###############################################################################
proc RefreshStatisticsList {} {
global ReturnValue
## Get the geometry of the register list
if {[scan [.systemResources.statistics.list configure -geometry] \
"-geometry geometry Geometry %s %d\x%d" dummy w h]!=3} {
set w 20
set h 10
}
## Get the list of statistics from the simulator
PutLine {ListStatistics}
set stat_list [GetList]
if {[llength $stat_list] == 0} { return 0 }
.systemResources.statistics.list delete 0 end
foreach i $stat_list {
.systemResources.statistics.list insert end "$i"
## Adjust the statistics list geometry if necessary
if {$w<[string length $i]} {
set w [expr [string length $i]+1]
.systemResources.statistics.list configure -geometry "$w\x$h"
}
}
return 1
}
###############################################################################
# Refresh the Register List
###############################################################################
proc RefreshRegisterList {} {
global ReturnValue
## Get the geometry of the register list
if {[scan [.systemResources.registers.list configure -geometry] \
"-geometry geometry Geometry %s %d\x%d" dummy w h]!=3} {
set w 20
set h 10
}
## Get the list of registers and values from the simulator
PutLine {ListRegisters}
.systemResources.registers.list delete 0 end
foreach i [GetList] {
.systemResources.registers.list insert end "$i"
## Adjust the register list geometry if necessary
if {$w<[string length $i]} {
set w [expr [string length $i]+1]
.systemResources.registers.list configure -geometry "$w\x$h"
}
}
}
###############################################################################
# Clear all of the registers (set them to zero)
###############################################################################
proc ClearAllRegisters {} {
## Set each of the registers to 0
PutLine {ListRegisters}
foreach i [GetList] {
scan $i "%s" name
PutLine "SetRegister $name 0"
## Remove any simulator output (should be just a Ready)
GetList
}
RefreshStatisticsList
RefreshRegisterList
RefreshProgramListing
}
###############################################################################
# Alter the value of a register
###############################################################################
proc AlterRegister {} {
## If no register is selected then leave
if {[llength [.systemResources.registers.list curselection]]==0} {
return
}
## Get the register name
scan [.systemResources.registers.list get [.systemResources.registers.list \
curselection]] "%s" name
set ReturnValue [ChildEntryDialog {} \
"Enter new value for register '$name':" {^[0-9a-fA-F]+$}]
# If Okay was pressed set the register value in the simulator
if {$ReturnValue != ""} {
PutLine "SetRegister $name $ReturnValue"
GetList
RefreshStatisticsList
RefreshRegisterList
RefreshProgramListing
}
}
###############################################################################
# Insert the statistics list into the trace window
###############################################################################
proc InsertStatisticsInTrace {} {
## Get the statistics list and put it in the trace window
PutLine {ListStatistics}
foreach i [GetList] {
.systemOutput.text insert end "$i\n"
.systemOutput.text yview -pickplace end
}
}
###############################################################################
# Insert the register list into the trace window
###############################################################################
proc InsertRegistersInTrace {} {
## Get the width of the trace window
if {[scan [.systemOutput.text configure -width] \
"-width width Width 80 %d" width] != "1"} {
set width "60"
}
## Get the register list and put it in the trace window
PutLine {ListRegisters}
set line ""
foreach i [GetList] {
if {[expr [string length $i]+[string length $line]]>$width} {
.systemOutput.text insert end "$line\n"
.systemOutput.text yview -pickplace end
set line "$i"
} else {
if {[string length $line]!=0} {
set line "$line $i"
} else {
set line "$i"
}
}
}
## Add the last line if there is one
if {[string length $line]!=0} {
.systemOutput.text insert end "$line\n\n"
.systemOutput.text yview -pickplace end
} else {
.systemOutput.text insert end "\n"
.systemOutput.text yview -pickplace end
}
}
###############################################################################
# Save the contents of the trace window to a file
###############################################################################
proc SaveTraceContents {} {
## Get the filename
set name [BtkFileSelector -text "Select file to append trace contents to:" \
-in .]
if {$name != ""} {
if {[file isdirectory $name]} {
ChildAlertDialog {} {ERROR: The name specified was a directory!!!}
return
}
set file [open $name "a+"]
set contents [.systemOutput.text get 1.0 end]
puts $file "$contents"
close $file
}
}
###############################################################################
# Load a program into the simulator
###############################################################################
proc LoadProgram {} {
set name [BtkFileSelector -text "Select program to load:" -in .]
if {$name!=""} {
if {[file isdirectory $name]} {
ChildAlertDialog {} {ERROR: The name specified was a directory!!!}
return
}
## Tell the simulator to load in the program
PutLine "LoadProgram 0 $name"
## Get any error message from the simulator and display it
set mess [lindex [GetList] 0]
if {$mess!=""} {
ChildAlertDialog {} "$mess"
}
RefreshMemoryViewer
}
}
###############################################################################
# Insert the execution trace record into the output window
###############################################################################
proc InsertStepTraceRecord {record} {
global Simulator
## Add the SimulatorMessage to the possible records/entries
set trace_records "{SimulatorMessage 40} $Simulator(TraceRecord)"
set entries "SimulatorMessage $Simulator(TraceEntries)"
foreach i $trace_records {
if {[scan $i "%s %d" name width]==2} {
if {[lsearch $entries $name] != -1} {
set i [lsearch -regexp $record "^$name"]
if {$i != -1} {
set field [lindex $record $i]
set t [format "%-$width\s" "[lindex $field 1]"]
.systemOutput.text insert end "$t "
.systemOutput.text yview -pickplace end
}
}
}
}
.systemOutput.text insert end "\n"
.systemOutput.text yview -pickplace end
}
###############################################################################
# Do a system reset on the simulator
###############################################################################
proc Reset {} {
PutLine "Reset"
GetList
## Refresh windows
RefreshStatisticsList
RefreshRegisterList
RefreshProgramListing
RefreshMemoryViewer
}
###############################################################################
# Step through some number of instructions
###############################################################################
proc Step {number} {
PutLine "Step $number"
foreach i [GetList] {
InsertStepTraceRecord "$i"
}
## Refresh windows
RefreshStatisticsList
RefreshRegisterList
RefreshProgramListing
RefreshMemoryViewer
}
###############################################################################
# Handle Running
###############################################################################
proc Run {} {
global Simulator
## Just in case destroy the window
catch {destroy .runningButton}
button .runningButton -text "Interrupt Execution!" \
-command {
## Send interrupt signal to the simulator
exec kill -INT $Simulator(Pid)
destroy .runningButton
}
place .runningButton -relx 0.5 -rely 0.5 \
-anchor center -relheight 0.2 -relwidth 0.4
## Wait for the window to become visibile
tkwait visibility .runningButton
## If input becomes availiable on the pipe then execution has stopped!
addinput -read $Simulator(Pipe) {destroy .runningButton}
## Start the program running
PutLine "Run"
## Make this a modal dialog
while {[catch {grab set .runningButton}] == 1} {}
tkwait window .runningButton
## Remove the input callback on the pipe file id
removeinput $Simulator(Pipe)
## Insert output from the simulator into the output window
foreach i [GetList] {
.systemOutput.text insert end "$i\n"
.systemOutput.text yview -pickplace end
}
## Refresh the Registers
RefreshStatisticsList
RefreshRegisterList
RefreshProgramListing
## Refresh the Registers
RefreshMemoryViewer
}
###############################################################################
# Refresh the list of breakpoints
###############################################################################
proc RefreshBreakpoints {} {
PutLine "ListBreakpoints"
.breakpoints.list.list delete 0 end
foreach i [lsort -ascii [GetList]] {
.breakpoints.list.list insert end "$i"
}
}
###############################################################################
# Break Point manipulation
###############################################################################
proc Breakpoints {} {
## Make sure the window is destroyed
catch {destroy .breakpoints}
## Create frame for breakpoint dialog
frame .breakpoints -relief raised -borderwidth 3
## Create the list of break points
frame .breakpoints.list
scrollbar .breakpoints.list.scroll -relief raised \
-command ".breakpoints.list.list yview"
listbox .breakpoints.list.list -relief raised \
-yscroll ".breakpoints.list.scroll set"
pack .breakpoints.list.scroll -side left -fill y
pack .breakpoints.list.list -side left -fill both -expand 1
## Create the add entry box
frame .breakpoints.add -relief raised -borderwidth 2
entry .breakpoints.add.entry -relief sunken
bind .breakpoints.add.entry <Return> {
if {[regexp {^[0-9a-fA-F]*$} [.breakpoints.add.entry get]]} {
PutLine "AddBreakpoint [.breakpoints.add.entry get]"
.breakpoints.add.entry delete 0 end
GetList ; RefreshBreakpoints
}
}
label .breakpoints.add.label -text "Add:"
pack .breakpoints.add.label -side left
pack .breakpoints.add.entry -side left -fill x -expand 1
button .breakpoints.remove -text "Remove" \
-command {
if {[llength [.breakpoints.list.list curselection]] != 0} {
foreach i [.breakpoints.list.list curselection] {
PutLine "DeleteBreakpoint [.breakpoints.list.list get $i]"
GetList
}
RefreshBreakpoints
}
}
button .breakpoints.dismiss -text "Dismiss" \
-command {destroy .breakpoints}
pack .breakpoints.list -side top -expand 1 -fill both -padx 2 -pady 2
pack .breakpoints.add -side top -fill x -expand 1 -padx 2 -pady 2
pack .breakpoints.remove -side left -fill x -expand 1 -padx 2 -pady 2
pack .breakpoints.dismiss -side left -fill x -expand 1 -padx 2 -pady 2
place .breakpoints -relx 0.5 -rely 0.5 -anchor center
## Set keyboard focus to the entry widget
focus .breakpoints.add.entry
RefreshBreakpoints
## Make this a modal dialog
tkwait visibility .breakpoints
while {[catch {grab set .breakpoints}] == 1} {}
tkwait window .breakpoints
}
###############################################################################
# Set the execution trace prefrences
###############################################################################
proc TracePreferences {} {
global Simulator
global ReturnValue
global TraceCheckButton
catch {destroy .tracePreferences}
## Create a frame for the dialog
frame .tracePreferences -relief raised -borderwidth 3
message .tracePreferences.message -width 2.5i -relief raised \
-text "Select trace fields to display:"
pack .tracePreferences.message -side top -padx 2 -pady 2
## Build a checkbutton for each trace record field
foreach i $Simulator(TraceRecord) {
if {[scan $i "%s" name]==1} {
checkbutton .tracePreferences.checkbutton$name -text $name \
-variable TraceCheckButton($name) -relief flat -anchor w
pack .tracePreferences.checkbutton$name -side top -fill x
if {[lsearch -exact $Simulator(TraceEntries) $name] != -1} {
set TraceCheckButton($name) 1
}
}
}
button .tracePreferences.ok -text "Okay" \
-command {set ReturnValue "Okay" ; destroy .tracePreferences}
button .tracePreferences.cancel -text "Cancel" \
-command {set ReturnValue "" ; destroy .tracePreferences}
pack .tracePreferences.ok -side left -expand 1 -fill x -padx 2 -pady 2
pack .tracePreferences.cancel -side left -expand 1 -fill x -padx 2 -pady 2
place .tracePreferences -relx 0.5 -rely 0.5 -anchor center
## Make this a modal dialog
tkwait visibility .tracePreferences
grab set .tracePreferences
tkwait window .tracePreferences
## If okay was pressed build the new Simulator(TraceEntries)
if {$ReturnValue!=""} {
set Simulator(TraceEntries) ""
foreach i $Simulator(TraceRecord) {
if {[scan $i "%s" name]==1} {
if {$TraceCheckButton($name) == 1} {
set Simulator(TraceEntries) "$i $Simulator(TraceEntries)"
}
}
}
}
unset TraceCheckButton
}
###############################################################################
# Load the simulator setup file and set everything up
###############################################################################
proc LoadSetup {name} {
global Simulator
global Program
## Shutdown the simulator if it is running
StopSimulator
## If a name wasn't supplied then pop up a file selector
if {$name == ""} {
set name [BtkFileSelector -text "Select a setup file to load:" \
-in . -filter "*.setup"]
}
if {$name!=""} {
if {[file exists $name] == 0} {
ChildAlertDialog {} {ERROR: Specified setup file does not exist!!!}
return
}
if {[file isdirectory $name]} {
ChildAlertDialog {} {ERROR: Specified setup file is a directory!!!}
return
}
set file [open $name "r"]
if {[gets $file]!="BSVC Simulator Setup File"} {
ChildAlertDialog {} "That file doesn't seem to be a simulator setup file!!!"
close $file
return
}
## read in the contents of the file
set contents [read $file]
close $file
if {[lsearch -exact "$contents" SIMULATOR]=="-1"} {
ChildAlertDialog {} "The Setup file seems to be corrupt!!!"
return
}
if {[StartSimulator "[lindex "$contents" [expr \
[lsearch -exact "$contents" SIMULATOR]+1]]"]==0} {
return
}
while {[lsearch -exact "$contents" COMMAND]!="-1"} {
## Get the next command
set index [lsearch -exact "$contents" COMMAND]
set command [lindex "$contents" [expr $index+1]]
## Send the command to the simulator
PutLine "$command"
set errs [lindex [GetList] 0]
## Remove the command from the contents
set contents [lreplace "$contents" $index [expr $index+1]]
}
SetApplicationMode {SimulationMode}
## Decided if the statistics list should be displayed
if {[RefreshStatisticsList] == "0"} {
pack forget .systemResources.statistics
} else {
pack .systemResources.statistics -after .systemResources.registers \
-side left -fill y
}
RefreshRegisterList
}
}
###############################################################################
# Save the simulator setup to a file
###############################################################################
proc SaveSetup {} {
global Simulator
global Program
set name [BtkFileSelector -text "Select a file to save the setup in:" \
-in . -filter "*.setup"]
if {$name!=""} {
if {[file isdirectory $name]} {
ChildAlertDialog {} {ERROR: The name specified was a directory!!!}
return
}
set file [open $name "w"]
puts $file "BSVC Simulator Setup File"
puts $file ""
puts $file "UI_VERSION \{$Program(Version)\}"
puts $file "SIMULATOR \{$Simulator(ProgramName)\}"
for {set t 0} {$t<$Simulator(NumberOfAddressSpaces)} {set t [expr $t+1]} {
## Get a list of devices attached to this address space
PutLine "ListAttachedDevices $t"
foreach i [GetList] {
puts $file "COMMAND \{AttachDevice $t $i\}"
}
}
close $file
}
}
###############################################################################
# Parse the command line arguments
###############################################################################
proc ParseCommandLineArguments {} {
global env
## Get the arguments from the environment variable
set args $env(ARGS)
## See if a setup file was named on the command line
if {[llength $args] == 1} {
LoadSetup [lindex $args 0]
}
if {[llength $args] > 1} {
ChildAlertDialog {} "Invalid number of command line arguments!!!"
}
}
###############################################################################
# Build the main drop down menu for the application
###############################################################################
frame .mainMenu -relief raised -borderwidth 2
menubutton .mainMenu.simulator -text "Simulator" -menu .mainMenu.simulator.menu
menu .mainMenu.simulator.menu
.mainMenu.simulator.menu add command -label "New Setup..." \
-command {NewSetup}
.mainMenu.simulator.menu add command -label "Load Setup..." \
-command {LoadSetup {}}
.mainMenu.simulator.menu add command -label "Edit Setup..." \
-command {EditSetup}
.mainMenu.simulator.menu add separator
.mainMenu.simulator.menu add command -label "Save Setup..." \
-command {SaveSetup}
.mainMenu.simulator.menu add separator
.mainMenu.simulator.menu add command -label "Quit" -command "QuitBSVC"
menubutton .mainMenu.system -text "System" -menu .mainMenu.system.menu
menu .mainMenu.system.menu
.mainMenu.system.menu add command -label "Load Program..." \
-command {LoadProgram}
.mainMenu.system.menu add separator
.mainMenu.system.menu add command -label "View Memory..." \
-command {OpenMemoryViewer}
.mainMenu.system.menu add command -label "Program Listing..." \
-command {OpenProgramListing}
.mainMenu.system.menu add command -label "Reset" \
-command {Reset}
menubutton .mainMenu.help -text "Help" -menu .mainMenu.help.menu
menu .mainMenu.help.menu
.mainMenu.help.menu add command -label "About $Program(Name)..." \
-command "About"
.mainMenu.help.menu add separator
.mainMenu.help.menu add command -label "License..." -command \
{HelpMe "$Program(HelpDir)/license.hlp" \
".licenseHelp" "License"}
.mainMenu.help.menu add command -label "General..." -command \
{HelpMe "$Program(HelpDir)/general.hlp" \
".generalHelp" "General Help"}
.mainMenu.help.menu add separator
.mainMenu.help.menu add command -label "Home Page..." -command \
{exec $Program(WWWBrowser) $Program(WWWHomePage) &}
if {$Program(WWWBrowser) == ""} {
.mainMenu.help.menu disable "Home Page..."
} else {
.mainMenu.help.menu enable "Home Page..."
}
pack .mainMenu.simulator -side left
pack .mainMenu.system -side left
pack .mainMenu.help -side left
tk_menuBar .mainMenu .mainMenu.simulator .mainMenu.system .mainMenu.help
###############################################################################
# Build the Internal System Resource area
###############################################################################
frame .systemResources
frame .systemResources.registers
frame .systemResources.registers.popslot -relief raised -borderwidth 2
menubutton .systemResources.registers.popup -text "Registers" \
-menu .systemResources.registers.popup.menu
menu .systemResources.registers.popup.menu
.systemResources.registers.popup.menu add command -label "Alter..." \
-command {AlterRegister}
.systemResources.registers.popup.menu add command -label "Clear All" \
-command {ClearAllRegisters}
.systemResources.registers.popup.menu add command -label "Description" \
-command {ChildAlertDialog "" "Function not implemented yet!"}
scrollbar .systemResources.registers.scroll -relief raised \
-command ".systemResources.registers.list yview"
listbox .systemResources.registers.list -relief raised \
-yscroll ".systemResources.registers.scroll set"
tk_listboxSingleSelect .systemResources.registers.list
bind .systemResources.registers.list <Double-1> "AlterRegister"
pack .systemResources.registers.popup -side top \
-in .systemResources.registers.popslot
pack .systemResources.registers.popslot -side top -fill x
pack .systemResources.registers.scroll -side left -fill y
pack .systemResources.registers.list -side left -fill y
frame .systemResources.statistics
frame .systemResources.statistics.popslot -relief raised -borderwidth 2
menubutton .systemResources.statistics.popup -text "Statistics" \
-menu .systemResources.statistics.popup.menu
menu .systemResources.statistics.popup.menu
.systemResources.statistics.popup.menu add command -label "Clear All" \
-command {ClearStatistics}
scrollbar .systemResources.statistics.scroll -relief raised \
-command ".systemResources.statistics.list yview"
listbox .systemResources.statistics.list -relief raised \
-yscroll ".systemResources.statistics.scroll set"
tk_listboxSingleSelect .systemResources.statistics.list
pack .systemResources.statistics.popup -side top \
-in .systemResources.statistics.popslot
pack .systemResources.statistics.popslot -side top -fill x
pack .systemResources.statistics.scroll -side left -fill y
pack .systemResources.statistics.list -side left -fill y
pack .systemResources.registers -side left -fill y
pack .systemResources.statistics -side left -fill y
###############################################################################
# Build the Control area
###############################################################################
frame .systemControl
button .systemControl.singleStep -text "Single Step" \
-command {Step "1"}
button .systemControl.step -text "Step"\
-command {Step "10"}
button .systemControl.run -text "Run" \
-command {Run}
button .systemControl.breakpoints -text "Breakpoints" \
-command {Breakpoints}
pack .systemControl.singleStep -side left -expand 1 -fill x
pack .systemControl.step -side left -expand 1 -fill x
pack .systemControl.run -side left -expand 1 -fill x
pack .systemControl.breakpoints -side left -expand 1 -fill x
###############################################################################
# Build the Output/Trace area
###############################################################################
frame .systemOutput
frame .systemOutput.popslot -relief raised -borderwidth 2
menubutton .systemOutput.popup -text "Trace" -menu .systemOutput.popup.menu
menu .systemOutput.popup.menu
.systemOutput.popup.menu add command -label "Save Contents..." \
-command {SaveTraceContents}
.systemOutput.popup.menu add command -label "Clear Contents" \
-command {.systemOutput.text delete 1.0 end}
.systemOutput.popup.menu add separator
.systemOutput.popup.menu add command -label "Insert Registers" \
-command {InsertRegistersInTrace}
.systemOutput.popup.menu add command -label "Insert Statistics" \
-command {InsertStatisticsInTrace}
.systemOutput.popup.menu add separator
.systemOutput.popup.menu add command -label "Trace Preferences..." \
-command {TracePreferences}
scrollbar .systemOutput.scroll -relief raised \
-command ".systemOutput.text yview"
text .systemOutput.text -relief raised -wrap none \
-yscroll ".systemOutput.scroll set" -borderwidth 2
bind .systemOutput.text <Any-KeyPress> "NOP"
pack .systemOutput.popup -side top \
-in .systemOutput.popslot
pack .systemOutput.popslot -side top -fill x
pack .systemOutput.scroll -side left -fill y
pack .systemOutput.text -side left -fill both -expand 1
pack .mainMenu -side top -fill x
pack .systemResources -side left -fill y
pack .systemControl -side bottom -fill x
pack .systemOutput -side bottom -expand 1 -fill both
SetApplicationMode {StartupMode}
ParseCommandLineArguments